#include "trajectory.h"

void initializeTrajectory(trajectory *trajectory_aux) {
	trajectory_aux->frame_count = 0;
}

void updateTrajectory(trajectory *trajectory_aux, CvRect box, CvPoint centroid) {
	trajectory_aux->centroids[trajectory_aux->frame_count].x = centroid.x;
	trajectory_aux->centroids[trajectory_aux->frame_count].y = centroid.y;
	trajectory_aux->boxes[trajectory_aux->frame_count] = box;
	trajectory_aux->frame_count++;
}

void drawTrajectory(IplImage *image, trajectory *trajectory_aux){
	for(int i = 0; i < trajectory_aux->frame_count-1; i++){
		cvLine(image, cvPoint( trajectory_aux->centroids[i].x,trajectory_aux->centroids[i].y),
					 cvPoint(trajectory_aux->centroids[i+1].x,trajectory_aux->centroids[i+1].y),
					 cvScalar(0,255,0),1,8);
	}
}

trajectory normalizeTrajectory (trajectory *trajectory_aux) {
	trajectory normalized;
	for (int i = 0; i < trajectory_aux->frame_count; i++) {
		normalized.centroids[i].x = trajectory_aux->centroids[i].x -trajectory_aux->centroids[0].x;
		normalized.centroids[i].y = trajectory_aux->centroids[i].y -trajectory_aux->centroids[0].y;
	}
	normalized.frame_count = trajectory_aux->frame_count;
	return normalized;
}